package com.rjkj.medicalwaste.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.rjkj.medicalwaste.bean.HospitalBean
import com.rjkj.medicalwaste.databinding.ItemHospitalListBinding

class SearchHospitalAdapter(var list: List<HospitalBean>, val itemClick: ItemClick<HospitalBean>) : RecyclerView.Adapter<SearchHospitalAdapter.ViewHolder>() {
    class ViewHolder(private val binding: ItemHospitalListBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item: HospitalBean, itemClick: ItemClick<HospitalBean>) {
            binding.bean = item
            binding.root.setOnClickListener {
                itemClick.onClicked(it, item)
            }
            binding.executePendingBindings()
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemHospitalListBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false)
        return ViewHolder(binding)

    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(list[position], itemClick)
    }

    override fun getItemCount(): Int {
        return list.size
    }
}